package com.cityeye.form;

import java.sql.Time;

import com.cityeye.dao.DepartmentDao;
import com.cityeye.entity.Department;
import com.cityeye.entity.Loginuser;

public class UserForm extends AbsEntityForm<Loginuser> {

	private Integer id;
	private Integer departmentId;
	private String username;
	private String password;
	private String old_password;
	private String new_password;
	private String new_password2;
	private Integer valid = 1;
	private Time lastlogin;
	private Integer role = 100;

	// Property accessors
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getDepartmentId() {
		return this.departmentId;
	}

	public void setDepartmentId(Integer department) {
		this.departmentId = department;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String name) {
		this.username = name;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNew_password() {
		return this.new_password;
	}

	public void setNew_password(String password) {
		this.new_password = password;
	}

	public String getOld_password() {
		return this.old_password;
	}

	public void setOld_password(String password) {
		this.old_password = password;
	}

	public String getNew_password2() {
		return this.new_password2;
	}

	public void setNew_password2(String password) {
		this.new_password2 = password;
	}

	public Integer getValid() {
		return this.valid;
	}

	public void setValid(Integer valid) {
		this.valid = valid;
	}

	public Time getLastlogin() {
		return this.lastlogin;
	}

	public void setLastlogin(Time lastlogin) {
		this.lastlogin = lastlogin;
	}

	public Integer getRole() {
		return this.role;
	}

	public void setRole(Integer role) {
		this.role = role;
	}

	public Loginuser toEntity() {
		Loginuser loginuser = new Loginuser();
		loginuser.setId(getId());
		loginuser.setName(getUsername());
		loginuser.setPassword(getPassword());
		loginuser.setRole(getRole());
		loginuser.setValid(getValid());

		Department parent_dept = null;
		if (getDepartmentId() != null) {
			DepartmentDao deptDao = new DepartmentDao();
			parent_dept = deptDao.findById(getDepartmentId());
		}

		loginuser.setDepartment(parent_dept);

		return loginuser;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return getUsername();
	}
}
